package com.tal.bcc.pad.cloud.coreprogress;

import okhttp3.MediaType;
import okhttp3.ResponseBody;
import okio.BufferedSource;
import okio.Okio;

class ProgressResponseBody extends ResponseBody {
    private final ResponseBody responseBody;
    private final ProgressCallback progressListener;
    private BufferedSource progressSource;

    ProgressResponseBody(ResponseBody responseBody, ProgressCallback progressListener) {
        this.responseBody = responseBody;
        this.progressListener = progressListener;
    }

    public MediaType contentType() {
        return this.responseBody.contentType();
    }

    public long contentLength() {
        return this.responseBody.contentLength();
    }

    public BufferedSource source() {
        if (this.progressListener == null) {
            return this.responseBody.source();
        } else {
            ProgressInputStream progressInputStream = new ProgressInputStream(this.responseBody.source().inputStream(), this.progressListener, this.contentLength());
            this.progressSource = Okio.buffer(Okio.source(progressInputStream));
            return this.progressSource;
        }
    }

    public void close() {
        if (this.progressSource != null) {
            try {
                this.progressSource.close();
            } catch (Exception var2) {
                Exception e = var2;
                e.printStackTrace();
            }
        }

    }
}